package com.yunlinker.asba.wxapi;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.yunlinker.asba.MainApplication;

import org.greenrobot.eventbus.EventBus;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {


	private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";

    private IWXAPI api;

    private Context mContext;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        api = WXAPIFactory.createWXAPI(this, MainApplication.APPID);
        api.handleIntent(getIntent(), this);
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {

	if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
      if(resp.errCode == 0){
          //success
//          UpLoadImg upLoadImg = new UpLoadImg();
//          upLoadImg.setStatusCode(result.getStatusCode());
//          upLoadImg.setBucketName(result.getBucketName());
//          upLoadImg.setLocation(result.getLocation());
          EventBus.getDefault().post("success");
      }else{
         //false
          EventBus.getDefault().post("error");
      }
    }
        finish();
	}
}
